<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>精选板块</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">									
			.fixedBox{
				border: 1px solid #696969;
				white-space: nowrap;
				
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
			p {margin-top:0px;margin-bottom:5px}				
			
			table{
				width:180px; 
				border-collapse:collapse; 
				text-align:center;				
			}
			td,th{
				border:1px solid #696969;
				color:#E1FFFF;  <!-- 表头文字颜色 -->
			}						
			td a:link{
				color:#E1FFFF;  <!-- 列表文字颜色 -->
			}
		</style>		
	</head>
	<body>		
		<div id="towrites" class="fixedBox" style="position:relative;float:left;display:none;">
			<div id="bar" style="margin:0px"></div>
			<div id="towrite"  class="fixedBox" style="position:relative; float:left;"></div>
			<div id="towritea" class="fixedBox" style="position:relative; float:left;border:none">
				<div id="towriter" class="fixedBox" style="position:relative; float:left;"></div>
			</div>
		</div>
		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script> 
		<script>
			var brcolor = $(".fixedBox").css("border");
			var bkcolor = $("body").css("backgroundColor");			
			var thcolor = "";
			var tdcolor = "";			
			var dt = "";
			var tt = "";
			var gt = "";
			var k = 0;		
			window.onload = function() {
				var day = new Date();
				gt = day.getTime();			
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;	
				dt = tt;
				changeStyle();
				getSource();				
			}
			
			var dssx = 0;			
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					dssx++;					
					if(dssx == 5){
						dssx = 0;
					}
					
					type = 6;
					order = 1;
					old = 0;
					rn = 2;
					
					getSource();
					//thclick();
					//changeTCss(objt,trid,"towrite3");
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
					if(k == 0){
						time_range("9:00","15:15")	
					}												
				},
				60000);
			})
						
			function changeStyle() {
				var obj = document.getElementById("towrites");
				obj.style.display= "block";
				//obj.style.border="2px solid #fff";
				obj.style.border= "none";
				obj.style.left= "0px"; 				
				obj.style.width= "98%";	
				obj.style.height= "350px";	
				obj.style.fontSize="12px";	
				
				var obj1 = document.getElementById("towrite");
				//obj1.style.border="1px solid #fff";				
				obj1.style.left= "0px"; 				
				obj1.style.width= "380px";	
				obj1.style.height= "90%";

				var obj2 = document.getElementById("towritea");	
				obj2.style.border="1px solid #696969";				
				obj2.style.left= "0px"; 				
				obj2.style.width= "68%";	
				obj2.style.height= "90%";	
				
				var obj3 = document.getElementById("towriter");	
				obj3.style.border= "none";
				//obj3.style.border="1px solid #fff";	
				obj3.style.left= "0px"; 
				obj3.style.width= "520%";
				obj3.style.height= "95%";	
			}						
						
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};			
			
			function NumberTransform(num) { 
				var result = num;
               if(Math.abs(num) > 100000000){
			    result = num / 100000000;
				result = result.toFixed(2) + "亿";
			   }else if(Math.abs(num) > 10000){
			    result = num/10000;
				result = result.toFixed(0) + "万";
			   }				   
               return result;  
			};			
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
									
			function cDayFunc(dp) { 
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function UnUnicode(str) {
				return unescape(str.replace(/\\/g, "%"));
			}
			
			window.onresize = function() {
				<!-- var h =  document.getElementById('towrite').offsetHeight ;				 -->
				<!-- var div = document.getElementById('towritea'); -->
				<!-- div.style.height = h - 20 + 'px';	 -->
			}
			
			function BookingRmk(date){         
				tt = date;
				var date1 = new Date(tt);
				var date2 = new Date(dt);						
				k = 0;
				if(date1.getTime() < date2.getTime()){			
					k = 1;					
					tradeday();					
				}
				
				type = 6;
				order = 1;
				old = 0;
				rn = 2;
				
				getSource();						
			}
			
			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);				
			}
			
			function next(){  //后一天 				
				pn = 1;
				var day = new Date(tt);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);							
			}
			
			var pn = -1;
			function tradeday() {  //判断最后交易日
				var day = new Date(tt);							
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() + pn*24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					if(tt == dt){	
						k = 0;
						getSource();
						break;
					}
					var url = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt; 			
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,						
						success: function(data) {							
							res = data.list;							
						}
					});
					if(res.length != 0){						
						break;
					}
				}
			}	
			
			function getSource() {				
				var diva = document.getElementById("bar");
				diva.innerHTML = '<font size="3" style="left:30px; color:#FFDAB9">精选板块</font>';
				//var sx = "<a style='left:30px; color:#00FF00' href='javascript:void(0)' onclick='getSource()'>" + "刷新" + "</a>";
				//diva.innerHTML = '<font size="3">' + sx + '</font>';
				
				var div = document.getElementById('towrite');																
				div.innerHTML = '<font size="2" style=color:#FFFF00;>精选板块</font><input style="width:90px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';		
				var back = '<a href="javascript:prev();"  style="padding-left:2px;font-size:16px;color:#fff;">←</a>';				
				var forward = '<a href="javascript:next();"  style="font-size:16px;color:#fff;">→</a>';
				div.innerHTML += back + forward ;
				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w21&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7"; 
				var url2 = "http://127.0.0.1:8881/w1/api/index.php?Order=1&a=RealRankingInfo&st=30&apiv=w26&Type=1&c=ZhiShuRanking&PhoneOSNew=1&ZSType=7&Date=" + tt; 			
				var url = url1;
				if(k == 1){
					url = url2;
				}				
				
				var dd = [];	
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));							
						if(k == 0){
							tt = data.Day;							
							dt = tt;
						}
						//alert(dt)
						var n = 0;
						for (i = 0; i < data.list.length; i++){
							var code = data.list[i][0];
							var name = data.list[i][1];							
							if(name.indexOf("ST") == -1){								
								n++;
								if(n == 11){
									break;
								}										
								res.push({"code":data.list[i][0],"name":data.list[i][1],"qd":data.list[i][2],"zf":data.list[i][3],"300w":NumberTransform(data.list[i][12]),"je":NumberTransform(data.list[i][6])});
								//dd += code + "," + name + "},{";
								dd.push({code,name});
							}
						}						
					}
				});				
				//document.write(JSON.stringify(dd));

				
				//var json = JSON.parse(bks);	
				var json = res;	
				//创建table					
				var table = document.createElement("table");										
				var thead = document.createElement("thead");
				table.appendChild(thead);					
				var tr = document.createElement("tr");
				thead.appendChild(tr);					
																				
				for(var key in json[0]){  //表头
					key = key.replace('code','代码').replace('name','名称').replace('qd','强度').replace('zf','涨幅%').replace('je','净额');										
					var th = document.createElement("th");						
					th.innerHTML = key;						
					tr.appendChild(th);							
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr = document.createElement("tr");
					var p = 1						
					for(var key in json[i]){ //行元素遍历						
						var td = document.createElement("td");														
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
						}		
						if(p == 4){
							rc = keepTwoDecimal(rc);
						}
						//td.innerHTML = rc
						td.innerHTML = "<a href='javascript:void(0)' id='" + p + "' onclick='changeCss(\"towrite" + dm + "\");Focus(\"towrite" + (i + 1) + "\")'>" + rc + "</a>";
						tr.appendChild(td);
						tr.id = "towrite" + dm;
						p++;							
					}
					$("table tr").find("td:eq(0)")
					tbody.appendChild(tr);											
				}									
				div.appendChild(table);
				//table.id = id;				
				
				changeTable(table,"0");		//隐藏某列				
				AddTableCell(table);   //添加序号列
				
				hovera();
									
				//延迟显示板块个股				
				setTimeout(loop, 100);
				var m = 0;
				function loop(){															
					var code = dd[m]["code"];
					var name = dd[m]["name"];
					m++;						
					bkgg(m,code,name);
					if( m < dd.length){
						setTimeout(loop, 100);
					}			
				};					
				document.getElementById("PriceDate").value = tt;
				
				//初始化高亮
				$("#towritea").scrollLeft (0);
				var tlist = document.getElementById("towriter").getElementsByTagName('div');
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.border = brcolor;					
				}	
			}
			
			//动态添加列
			function AddTableCell(table){
				var Table = table			   
				var rowLength = Table.rows.length;  //行數量
				//var cellLength=Table.rows[0].cells.length; //查找單元格数量
				for(var i = 0; i < rowLength; i++){					
					var NewCell1 = Table.rows[i].insertCell(0);
					var NewCell2 = Table.rows[i].insertCell(5);
					if(i == 0){
						NewCell1.innerHTML = "序号";
						NewCell2.innerHTML = "涨停";
						if(dssx == 0){  //定时刷新
							dzts = "";					
						}
					}else{
						NewCell1.innerHTML = i;
						NewCell2.innerHTML = "";
						var dm = Table.rows[i].cells[1].innerText;
						NewCell2.id = tt + dm;
						if(localStorage.getItem('ldbkzts' + NewCell2.id) != null) {   //判断有无板块涨停数缓存数据														
							var zts = localStorage.getItem('ldbkzts' + NewCell2.id);    //取缓存数据							
							NewCell2.innerHTML = zts;							
						}else if(dt == tt){
							lastday(tt, dm);
						}					
					}					
				}						
			}
			
			var dzts = "";  // 当日涨停数
			function lastday(tt, dm){
				<!-- if(dssx == 0){  //定时刷新 -->
					<!-- dzts = "";					 -->
				<!-- } -->
				<!-- alert(dzts)				 -->
				var tdiv = document.getElementById(tt + dm);	
				if(dzts.indexOf(tt + dm + "=") > -1){
					tdiv.innerHTML = dzts.split(tt + dm + "=")[1].split(";")[0];
				}else{	
					var url = "http://127.0.0.1:8880/w1/api/index.php?Order=1&st=60&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=1&apiv=w21&Type=6&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + dm; 																													
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,					
						success: function(data) {											
							//document.write(JSON.stringify(data));														
							for (i = 0; i < data.list.length; i++){
								var lbs = data.list[i][23];
								if(lbs != ""){
									res.push({"code":data.list[i][0],"name":data.list[i][1],"lb":data.list[i][23]});							
								}
							}							
						}
					});	
					//document.write(JSON.stringify(res));
					
					//涨停数
					var zts = 0;
					if(res.length != 0){					
						for(var i = 0; i < res.length; i++){
							var aa = res[i]["lb"];
							if(aa.indexOf("昨") == -1){
								zts++;
							}					
						}						
					}					
					tdiv.innerHTML = zts;
					dzts += tt + dm + "=" + zts + ";";
				}
			}
			
			function Focus(id){  //移动					
				//alert(id)				
				var tlist = document.getElementById("towriter").getElementsByTagName('div');
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.border = brcolor;					
				}	
				var div = document.getElementById(id);				
				div.style.border = "3px solid #FFA500";
				$("#" + id).scrollTop (0);
				
				var x = div.offsetLeft;
				$("#towritea").scrollLeft (x);				
			}
			
			var rid = "";
			function changeCss(id){	
				rid = id;
				var tlist = document.getElementById("towrite").getElementsByTagName('tr');					
				for(var i = 0; i < tlist.length; i++){														
					tlist[i].style.backgroundColor = bkcolor;					
				}				
				var tr = document.getElementById(id);				
				tr.style.backgroundColor = "#483D8B";						
			}
			
			function hovera(){  //鼠标经过					
				//var rows = document.getElementsByTagName('tr');
				var rows = document.getElementById("towrite").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头						
							if(rid == this.id){
								this.style.background ="#483D8B";							
							}else{
								this.style.background = bkcolor;						
							}							
						}						
					}					
				}
			}
			
			var bkdm = "";
			var bkmc = "";	
			var type = 6;
			var order = 1;
			var old = 0;
			var rn = 2;
			function bkgg(n,code,name){	
				bkdm = code;
				bkmc = name;
				var newDiv = document.getElementById("towrite" + n);
				if(!newDiv){
					//添加分类Div				
					var newDiv = document.createElement("div");
					newDiv.id = "towrite" + n;
					newDiv.className = "fixedBox";
					newDiv.style.left = "0px"; 	
					newDiv.style.width = "450px";
					newDiv.style.height = "98%";
					newDiv.style.position = "relative"; 
					newDiv.style.float = "left";
					newDiv.style.fontSize="12px";
					newDiv.style.whiteSpace = "nowrap";	
					document.getElementById("towriter").appendChild(newDiv);
				}				
				newDiv.innerHTML = "<font size='2' style=color:#FFFF00;>" + name + "</font>";				
				var url1 = "http://127.0.0.1:8880/w1/api/index.php?Order=" + order + "&st=30&a=ZhiShuStockList_W8&c=ZhiShuRanking&PhoneOSNew=1&old=" + old + "&apiv=w21&Type=" + type + "&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + code; 								
				var url2 = "http://127.0.0.1:8881/w1/api/index.php?st=30&Index=0&old=" + old + "&Order=" + order + "&a=ZhiShuStockList_W8&apiv=w26&Type=" + type + "&c=ZhiShuRanking&PhoneOSNew=1&DeviceID=6575961a-b25b-3831-aa2b-4a373b51b256&VerSion=5.12.0.0&PlateID=" + code + "&Date=" + tt;				
				var url = url1;
				if(k == 1){
					url = url2;
				}				
				var res = [];
				$.ajax({
					type: "get",
					url: url,
					dataType: "json",
					async : false,
					cache:false,
					timeout:3000,					
					success: function(data) {
						//alert(JSON.stringify(data))						
						//document.write(JSON.stringify(data));														
						for (i = 0; i < data.list.length; i++){
							res.push({"code":data.list[i][0],"name":data.list[i][1],"zf":data.list[i][6],"lb":data.list[i][23],"300w":NumberTransform(data.list[i][50]),"je":NumberTransform(data.list[i][13]),"bk":data.list[i][4]});							
						}											
					}
				});				
				//document.write(data);
				
				//var json = JSON.parse(data);
				var json = res;	
				//创建table					
				var table=document.createElement("table");										
				var thead=document.createElement("thead");
				table.appendChild(thead);					
				var tr=document.createElement("tr");
				thead.appendChild(tr);					
				
				var m = 0;
				var v = 0;
				var b = 0;
				bj = [];
				for(var key in json[0]){  //表头													
					key = key.replace('code','代码').replace('name','名称').replace('zf','涨幅%').replace('lb','连板').replace('bk','板块').replace('je','净额');
					var th=document.createElement("th");						
					th.innerHTML=key;						
					tr.appendChild(th);	
					if(key == "连板" || key == "板块"){
						bj.push(m);
						th.style.color = "#FFA500";	
					}						
					if(m == rn){
						th.style.color = "#FFFF80";						
					}
					m++;
				}
									
				var tbody=document.createElement("tbody");					
				table.appendChild(tbody);
				
				//遍历json
				for(var i = 0; i < json.length; i++){					
					var tr=document.createElement("tr");						
					var p = 1;	
					var dm = "";
					var mc = "";					
					for(var key in json[i]){ //行元素遍历					
						var td=document.createElement("td");							
						
						var rc = json[i][key];
						if(p == 1){  //代码列
							dm = rc;
							tr.id = dm + "##" + code;
						}						
						td.innerHTML = "<a href=http://www.treeid/code_" + dm + " id='" + p + "' onclick='changeTCss(\"" + newDiv.id + "\",\"" + tr.id + "\")'>" + rc + "</a>";
							
						if(bj.indexOf(p - 1) > -1){	
							td.getElementsByTagName("a")[0].style.color = "#FFA500";  
						}
						
						if(p == rn + 1){														
							var value = parseFloat(JSON.stringify(rc).replace('万','').replace('亿','').replace(/"/,''));
							if(!isNaN(parseFloat(value)) && isFinite(value)){  //判断列是否为数字
								if(value >= 0){
									td.getElementsByTagName("a")[0].style.color = "#FF6633";
								}else{
									td.getElementsByTagName("a")[0].style.color = "#00FF00";
								}
							}else{								
								td.getElementsByTagName("a")[0].style.color = "#FF6633";								
							}
						}
						
						if(rc == "破板"){
							td.getElementsByTagName("a")[0].style.color = "#00FF00"; 
						}
						tr.appendChild(td);
						p++;
					}						
					tbody.appendChild(tr);
				}									
				newDiv.appendChild(table);
				table.id = n + "#" + code + "#" + name;					
				changeTable(table,"0");		//隐藏某列	
				
				makeSortable(table);			
				hover();				
			}
						
			//隐藏某列				
            function changeTable(table,ss) {	
				var trs = table.rows;
				ss = ss + '#';
				var aa = ss.split('#');
				for (var j = 0; j < aa.length; j++) {
					if(aa[j] != ""){
						for (var i = 0, len = trs.length; i < len; i++) {					
							var p = aa[j];
							var cell = trs[i].cells[p]; 
							cell.style.display = 'none';
						}
					}
				}					
			}
			
			var trid = "";
			function changeTCss(tid,id){				
				trid = id;
				var dm = id.split("##")[0];
				var bk = id.split("##")[1];
				var tlist = document.getElementById("towriter").getElementsByTagName("tr");					
				for(var i = 0; i < tlist.length; i++){
					var dms = tlist[i].id.split("##")[0];
					var bks = tlist[i].id.split("##")[1];					
					if(dms == dm){
						tlist[i].style.backgroundColor = "#483D8B";						
						if(bks != bk){
							var t = tlist[i].parentNode.parentNode.parentNode.id;  //td父节点tr id							
							$("#" + t).scrollTop (0);												
							var y = getTop(tlist[i]);  //纵坐标
							var div = document.getElementById(t);						
							if(y > div.clientHeight){						
								$("#" + t).scrollTop (y - 100);  //控制滚动条
							}
						}
					}else{
						tlist[i].style.backgroundColor = bkcolor;
					}					
				}				
				//var tr = document.getElementById(id);				
				//tr.style.backgroundColor = "#483D8B";						
			}
			
			//获取元素的纵坐标 
			function getTop(e){ 
				var offset=e.offsetTop; 
				if(e.offsetParent!=null) offset+=getTop(e.offsetParent);				
				return offset; 
			} 		
			
			function hover(){  //鼠标经过					
				var rows = document.getElementById("towriter").getElementsByTagName('tr');
				for(var i=0;i<rows.length;i++){
					rows[i].onmouseover=function(){							
						if(this.id != ""){  //过滤表头
							this.style.background="#800000";
						}
					}
					rows[i].onmouseout=function(){
						if(this.id != ""){  //过滤表头						
							if(trid == this.id){
								this.style.background ="#483D8B";							
							}else{
								this.style.background = bkcolor;						
							}							
						}						
					}					
				}
			}
			
			var sfx = 0;  //自动刷新开关
			var fls = false;  //排序方向
			function makeSortable(table) {
				var headers=table.getElementsByTagName("th");
				for(var i=0;i<headers.length;i++){				
					(function(n){
						var flag=false;
							
						headers[n].onclick=function(){
						//alert(n)
							var ss = table.id.split("#");							
							rn = n;
							
							if(n == 2 || n == 4 || n == 5){
								if(n == 2){		       //涨幅													
									old = 0;
									type = 6;																																		
								}else if(n == 4){	    //300w						
									type = 28;
								}else if(n == 5){	    //净额						
									type = 1;
								}
														
								if(order == 1){
									order = 0;									
								}else{
									order = 1;									
								}								
								bkgg(ss[0],ss[1],ss[2]);
							}else{
								if(type != 6 || old != 1){
									type = 6;
									old = 1;
									order = 1;
									bkgg(ss[0],ss[1],ss[2]);
								}
								showCol(table,n,bj);		//高亮
							}
							
							var tbody=table.tBodies[0];
							var rows=tbody.getElementsByTagName("tr");
							rows=Array.prototype.slice.call(rows,0);

							//基于第n个<td>元素的值对行排序
							rows.sort(function(row1,row2){
								headtxt = headers[n].textContent;								
								var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格
								var cell2=row2.getElementsByTagName("td")[n];																
								var val1=cell1.textContent||cell1.innerText;//获得文本内容
								var val2=cell2.textContent||cell2.innerText;
								if(headtxt.indexOf("名称") != -1 || headtxt=="板块"){
									val1 = val1;
									val2 = val2;
								}else if(headtxt.indexOf("连板") != -1){								
									val1 = val1.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val1.indexOf("天")>-1){
										val1 = val1.split("天")[0];
									}else if(val1.indexOf("昨")>-1){
										val1 = 0;
									}else if(val1 == ""){
										val1 = -2;
									}										
									val1 = parseFloat(val1);
								
									val2 = val2.replace("昨日首板","-1").replace("首板","1").replace("连板","");
									if(val2.indexOf("天")>-1){
										val2 = val2.split("天")[0];
									}else if(val2.indexOf("昨")>-1){
										val2 = 0;
									}else if(val2 == ""){
										val2 = -2;
									}									
									val2 = parseFloat(val2);
								}else if(headtxt.indexOf("领涨") != -1){
									val1 = val1.replace("龙十","龙一十").replace("破板","1000");
									val2 = val2.replace("龙十","龙一十").replace("破板","1000");
									if(val1 == ''){
										val1 = '1001';
									}
									if(val2 == ''){
										val2 = '1001';
									}
									if(val1.indexOf("龙") != -1){
										val1 = ChineseToNumber(val1.replace("龙",""));										
									}										
									if(val2.indexOf("龙") != -1){
										val2 = ChineseToNumber(val2.replace("龙",""));
										
									}
									//val2 = parseFloat(val2);									
								}else{
									if(val1 == "-"){
										val1 = " ";
									}
									if(val2 == "-"){
										val2 = " ";
									}
									val1 = val1.replace(" ","0").replace("无","1000").replace("NaN","0");
									val2 = val2.replace(" ","0").replace("无","1000").replace("NaN","0");
									if(val1.indexOf("万") != -1){
										val1 = parseFloat(val1)*10000;
									}else if(val1.indexOf("亿") != -1){
										val1 = parseFloat(val1)*100000000;
									}else{
										val1 = parseFloat(val1);
									}
									
									if(val2.indexOf("万") != -1){
										val2 = parseFloat(val2)*10000;
									}else if(val2.indexOf("亿") != -1){
										val2 = parseFloat(val2)*100000000;
									}else{
										val2 = parseFloat(val2);
									}
								}
								if(val1<val2){
									return -1;
								}else if(val1>val2){
									return 1;
								}else{
									return 0;
								}
								
							});
							
							if(sfx == 1){   //自动刷新时，保持排序方向
								flag = fls;								
							}
							fls = flag;							
							sfx = 0;

							if(flag){
								rows.reverse();								
							}
							
							for(var i=0;i<rows.length;i++){
								tbody.appendChild(rows[i]);
							}
							
							flag=!flag;									
						}
					}(i));
				}
			}
			
			function showCol(table,iCol,arr){	 //(选中列，标记列)	
				var oTable = table;						
				//表头
				var th = oTable.getElementsByTagName("th");						
				for (var i=0;i < th.length; i++){	    //列遍历
					th[i].style.color = thcolor;      //还原					
					if(arr.length > 0 && arr.indexOf(i) > -1){  //BJ列高亮
						th[i].style.color = "#FFA500";
					}
					th[iCol].style.color = "#FFFF80";	//选中				
				}
				
				var tr = oTable.getElementsByTagName("tr");	
				for (var i=1;i < tr.length; i++){	//行遍历
					var otagsA = tr[i].getElementsByTagName("a");
					for (var j=0;j < otagsA.length; j++){	//列遍历
						otagsA[j].style.color = thcolor;	//还原																
						if(arr.length > 0 && arr.indexOf(j) > -1){  //BJ列高亮
							otagsA[j].style.color = "#FFA500";
						}
					}
					var value = otagsA[iCol].innerText.replace(/(万)|(亿)/g,'');
					if(!isNaN(parseFloat(value)) && isFinite(value)){  //判断列是否为数字
						if(parseFloat(value) >= 0){
							otagsA[iCol].style.color = "#FF6633";     //正负颜色
						}else{
							otagsA[iCol].style.color = "#00FF00";
						}
					}else{
						otagsA[iCol].style.color = "#FF6633";
					}
					
					//破板
					for (var j=0;j < otagsA.length; j++){	//列遍历
						var value = otagsA[j].innerText;
						if(value == "破板"){
							otagsA[j].style.color = "#00FF00";
						}
					}		
				}					
			}	
			
			var chnNumChar = {零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9};

			var chnNameValue = {
			  十:{value:10, secUnit:false},
			  百:{value:100, secUnit:false},
			  千:{value:1000, secUnit:false},
			  万:{value:10000, secUnit:true},
			  亿:{value:100000000, secUnit:true}
			}

			function ChineseToNumber(chnStr){
			  var rtn = 0;
			  var section = 0;
			  var number = 0;
			  var secUnit = false;
			  var str = chnStr.split('');

			  for(var i = 0; i < str.length; i++){
				var num = chnNumChar[str[i]];
				if(typeof num !== 'undefined'){
				  number = num;
				  if(i === str.length - 1){
					section += number;
				  }
				}else{
				  var unit = chnNameValue[str[i]].value;
				  secUnit = chnNameValue[str[i]].secUnit;
				  if(secUnit){
					section = (section + number) * unit;
					rtn += section;
					section = 0;
				  }else{
					section += (number * unit);
				  }
				  number = 0;
				}
			  }
			  return rtn + section;
			}
			
			<!-- function makeSortable(table) {		 -->
				<!-- var headers=table.getElementsByTagName("th"); -->
				<!-- for(var i=0;i<headers.length;i++){				 -->
					<!-- (function(n){ -->
						<!-- var flag=false; -->
							
						<!-- headers[n].onclick=function(){											 -->
							<!-- showCol(table,n);		//高亮 -->
							<!-- var tbody=table.tBodies[0]; -->
							<!-- var rows=tbody.getElementsByTagName("tr"); -->
							<!-- rows=Array.prototype.slice.call(rows,0); -->

							<!-- //基于第n个<td>元素的值对行排序 -->
							<!-- rows.sort(function(row1,row2){ -->
								<!-- headtxt = headers[n].textContent;								 -->
								<!-- var cell1=row1.getElementsByTagName("td")[n];//获得第n个单元格 -->
								<!-- var cell2=row2.getElementsByTagName("td")[n];																 -->
								<!-- var val1=cell1.textContent||cell1.innerText;//获得文本内容 -->
								<!-- var val2=cell2.textContent||cell2.innerText; -->
								<!-- if(headtxt.indexOf("名称") != -1 || headtxt.indexOf("主力") != -1|| headtxt.indexOf("主题") != -1){ -->
									<!-- val1 = val1; -->
									<!-- val2 = val2; -->
								<!-- }else if(headtxt.indexOf("连板") != -1){								 -->
									<!-- val1 = val1.replace("昨日首板","-1").replace("首板","1").replace("连板",""); -->
									<!-- if(val1.indexOf("天")>-1){ -->
										<!-- val1 = val1.split("天")[0]; -->
									<!-- }else if(val1.indexOf("昨")>-1){ -->
										<!-- val1 = 0; -->
									<!-- }else if(val1 == ""){ -->
										<!-- val1 = -2; -->
									<!-- }										 -->
									<!-- val1 = parseFloat(val1); -->
								
									<!-- val2 = val2.replace("昨日首板","-1").replace("首板","1").replace("连板",""); -->
									<!-- if(val2.indexOf("天")>-1){ -->
										<!-- val2 = val2.split("天")[0]; -->
									<!-- }else if(val2.indexOf("昨")>-1){ -->
										<!-- val2 = 0; -->
									<!-- }else if(val2 == ""){ -->
										<!-- val2 = -2; -->
									<!-- }									 -->
									<!-- val2 = parseFloat(val2); -->
								<!-- }else{											 -->
									<!-- if(val1.indexOf("万") != -1){ -->
										<!-- val1 = parseFloat(val1)*10000; -->
									<!-- }else if(val1.indexOf("亿") != -1){ -->
										<!-- val1 = parseFloat(val1)*100000000; -->
									<!-- }else{ -->
										<!-- val1 = parseFloat(val1); -->
									<!-- } -->
									
									<!-- if(val2.indexOf("万") != -1){ -->
										<!-- val2 = parseFloat(val2)*10000; -->
									<!-- }else if(val2.indexOf("亿") != -1){ -->
										<!-- val2 = parseFloat(val2)*100000000; -->
									<!-- }else{ -->
										<!-- val2 = parseFloat(val2); -->
									<!-- } -->
								<!-- } -->
								<!-- if(val1<val2){ -->
									<!-- return -1; -->
								<!-- }else if(val1>val2){ -->
									<!-- return 1; -->
								<!-- }else{ -->
									<!-- return 0; -->
								<!-- } -->
							<!-- }); -->
							<!-- if(flag){ -->
								<!-- rows.reverse(); -->
							<!-- } -->
							
							<!-- for(var i=0;i<rows.length;i++){ -->
								<!-- tbody.appendChild(rows[i]); -->
							<!-- } -->

							<!-- flag=!flag; -->
						<!-- } -->
					<!-- }(i)); -->
				<!-- } -->
			<!-- } -->
			
			<!-- function showCol(table,iCol){			 -->
				<!-- var oTable = table; -->
				<!-- var id = oTable.id; -->
				<!-- for (i=0;i < oTable.rows.length; i++){										 -->
					<!-- for (j=0;j < oTable.rows[0].cells.length; j++){ -->
						<!-- //alert(oTable.rows[i].cells[3].innerText) -->
						<!-- oTable.rows[i].cells[j].style.color = thcolor; -->
						<!-- //if(oTable.id != "towrite6"){ -->
							<!-- oTable.rows[i].cells[3].style.color = "#FFA500"; -->
						<!-- //}						 -->
					<!-- } -->
					<!-- oTable.rows[i].cells[iCol].style.color = "#FF6633";					 -->
				<!-- } -->
				
				<!-- var otagsA = oTable.getElementsByTagName("a");  //a变色 -->
				<!-- for (i = 0; i < otagsA.length; i++) { -->
					<!-- otagsA[i].style.color = tdcolor; -->
					<!-- if(otagsA[i].id == 4){ -->
						<!-- otagsA[i].style.color = "#FFA500"; -->
					<!-- }	 -->
					<!-- if(otagsA[i].id == iCol + 1){ -->
						<!-- otagsA[i].style.color = "#FF6633"; -->
					<!-- } -->
				<!-- }				 -->
			<!-- } -->
			
		</script>		
	</body>
</html>